package cn.shopping.controller.ordermanage;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;


import cn.shopping.pojo.Ch_delivery;
import cn.shopping.service.ordermanage.OrderManageService;

@Controller
@RequestMapping("/ordermanage")
public class OrderManageController {

	@Resource
	private OrderManageService orderManagement;
	/**
	 * 查询已发货列表
	 * @param session
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/shippinglist.html",method=RequestMethod.GET)
	public String getShippingList(HttpSession session,Model model){
		List<Ch_delivery> list = orderManagement.findshippinglist();
		model.addAttribute("shippinglist", list);
		return "yifahuoliebiao";
	}
	
	/**
	 * 查看已发货列表详情
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/shippingdetails/{id}")
	public String getShippingdetails(@PathVariable Integer id,Model model){
		int sid=id;
		if(sid>0){
			List<Ch_delivery> list = orderManagement.findorderdetails(sid);
			model.addAttribute("shipping", list);
			return "yifahuoliebiaoxiangqing";
		}
		
		return "redirect:/ordermanage/shippinglist.html";
	}
	
	/***
	 * 查询已完成列表
	 * @param session
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/completedlist.html",method=RequestMethod.GET)
	public String getcompletedList(HttpSession session,Model model){
		List<Ch_delivery> list = orderManagement.AllCompletedList();
		model.addAttribute("comleted", list);
		return "yiwanchengliebiao";
	}
	
	
	/**
	 * 查询已完成列表详情信息
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/completeddetails/{id}")
	public String getCompletedDetails(@PathVariable Integer id,Model model){
		int cid=id;
		if(cid>0){
			List<Ch_delivery> list = orderManagement.findorderdetails(cid);
			model.addAttribute("completed", list);
			return "yiwanchengliebiaoxiangqing";
		}
		return "redirect:/ordermanage/completedlist.html";
	}
	
	/***
	 * 查询订单列表
	 * @param session
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/orderlist.html")
	public String getorderlist(
			@RequestParam(value="order_no", defaultValue = "", required = false) String order_no,
			@RequestParam(value="product_name", defaultValue = "", required = false) String product_name,
			@RequestParam(value="statusName", defaultValue = "", required = false) String statusName,
			@RequestParam(value="order_time", defaultValue = "", required = false) String order_time,
			@RequestParam(value="end_time", defaultValue = "", required = false) String end_time,
			Model model){
		List<Ch_delivery> list = orderManagement.getshippinglist(order_no, product_name, statusName, order_time, end_time);
		model.addAttribute("orderlist", list);
		return "dingdanliebiao";
	}
	
	/**
	 * 查询订单列表详情信息
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/orderdetails/{id}")
	public String getOrderDetails(@PathVariable Integer id,Model model){
		int cid=id;
		if(cid>0){
			List<Ch_delivery> list = orderManagement.findorderdetails(cid);
			model.addAttribute("completed", list);
			return "dindanliebiaoxiangqing";
		}
		return "redirect:/ordermanage/orderlist.html";
	}
	
	
	/**
	 * 删除已发货信息
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/delshipping/{id}")
	public String delShippingOrders(@PathVariable Integer id){
		int sid = id;
		if(orderManagement.delshipping(sid)){
			return "redirect:/ordermanage/shippinglist.html";
		}
		return "redirect:/ordermanage/shippinglist.html";
	}
	
	/**
	 * 删除已完成信息
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/delcompleted/{id}")
	public String delCompletedList(@PathVariable Integer id){
		int cid = id;
		if(orderManagement.delCompletedList(cid)){
			return "redirect:/ordermanage/completedlist.html";
		}
		return "redirect:/ordermanage/completedlist.html";
	}
	
	/**
	 * 删除订单信息
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/delorderlist/{id}")
	public String delorder(@PathVariable Integer id){
		int oid = id;
		if(orderManagement.delorderlist(oid)){
			return "redirect:/ordermanage/orderlist.html";
		}
		return "redirect:/ordermanage/orderlist.html";
	}
}
